﻿using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using BestEasyCMS.Framework.Configuration;
using BestEasyCMS.Framework.Email;
using BestEasyCMS.Framework.Logging;
using BestEasyCMS.Service.Cache;
using StructureMap;

namespace BestEasyCMS.Web.MvcUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            ControllerBuilder.Current.SetControllerFactory(new IoCControllerFactory());

            Service.BootStrapper.ConfigureAutoMapper();
            BootStrapper.ConfigureDependencies();

            ApplicationSettingsFactory.InitializeApplicationSettingsFactory(ObjectFactory.GetInstance<IApplicationSettings>());
            EmailServiceFactory.InitializeEmailServiceFactory(ObjectFactory.GetInstance<IEmailService>());
            LoggingFactory.InitializeLogFactory(ObjectFactory.GetInstance<ILogger>());

            //启动缓存
            CacheHelper.Start();
        }
    }
}